<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>entry.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_fs_entry.js.html">entry.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Wrappers for HTML5 Entry objects. These are all in the same
<a name="line17"></a> * file to avoid circular dependency issues.
<a name="line18"></a> *
<a name="line19"></a> * When adding or modifying functionality in this namespace, be sure to update
<a name="line20"></a> * the mock counterparts in goog.testing.fs.
<a name="line21"></a> *
<a name="line22"></a> */
<a name="line23"></a>
<a name="line24"></a>goog.provide(&#39;goog.fs.DirectoryEntry&#39;);
<a name="line25"></a>goog.provide(&#39;goog.fs.DirectoryEntry.Behavior&#39;);
<a name="line26"></a>goog.provide(&#39;goog.fs.Entry&#39;);
<a name="line27"></a>goog.provide(&#39;goog.fs.FileEntry&#39;);
<a name="line28"></a>
<a name="line29"></a>goog.require(&#39;goog.array&#39;);
<a name="line30"></a>goog.require(&#39;goog.async.Deferred&#39;);
<a name="line31"></a>goog.require(&#39;goog.fs.Error&#39;);
<a name="line32"></a>goog.require(&#39;goog.fs.FileWriter&#39;);
<a name="line33"></a>goog.require(&#39;goog.functions&#39;);
<a name="line34"></a>goog.require(&#39;goog.string&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * The abstract class for entries in the filesystem.
<a name="line40"></a> *
<a name="line41"></a> * @param {!goog.fs.FileSystem} fs The wrapped filesystem.
<a name="line42"></a> * @param {!Entry} entry The underlying Entry object.
<a name="line43"></a> * @constructor
<a name="line44"></a> */
<a name="line45"></a>goog.fs.Entry = function(fs, entry) {
<a name="line46"></a>  /**
<a name="line47"></a>   * The wrapped filesystem.
<a name="line48"></a>   *
<a name="line49"></a>   * @type {!goog.fs.FileSystem}
<a name="line50"></a>   * @private
<a name="line51"></a>   */
<a name="line52"></a>  this.fs_ = fs;
<a name="line53"></a>
<a name="line54"></a>  /**
<a name="line55"></a>   * The underlying Entry object.
<a name="line56"></a>   *
<a name="line57"></a>   * @type {!Entry}
<a name="line58"></a>   * @private
<a name="line59"></a>   */
<a name="line60"></a>  this.entry_ = entry;
<a name="line61"></a>};
<a name="line62"></a>
<a name="line63"></a>
<a name="line64"></a>/**
<a name="line65"></a> * @return {boolean} Whether or not this entry is a file.
<a name="line66"></a> */
<a name="line67"></a>goog.fs.Entry.prototype.isFile = function() {
<a name="line68"></a>  return this.entry_.isFile;
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>/**
<a name="line73"></a> * @return {boolean} Whether or not this entry is a directory.
<a name="line74"></a> */
<a name="line75"></a>goog.fs.Entry.prototype.isDirectory = function() {
<a name="line76"></a>  return this.entry_.isDirectory;
<a name="line77"></a>};
<a name="line78"></a>
<a name="line79"></a>
<a name="line80"></a>/**
<a name="line81"></a> * @return {string} The name of this entry.
<a name="line82"></a> */
<a name="line83"></a>goog.fs.Entry.prototype.getName = function() {
<a name="line84"></a>  return this.entry_.name;
<a name="line85"></a>};
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * @return {string} The full path to this entry.
<a name="line90"></a> */
<a name="line91"></a>goog.fs.Entry.prototype.getFullPath = function() {
<a name="line92"></a>  return this.entry_.fullPath;
<a name="line93"></a>};
<a name="line94"></a>
<a name="line95"></a>
<a name="line96"></a>/**
<a name="line97"></a> * @return {!goog.fs.FileSystem} The filesystem backing this entry.
<a name="line98"></a> */
<a name="line99"></a>goog.fs.Entry.prototype.getFileSystem = function() {
<a name="line100"></a>  return this.fs_;
<a name="line101"></a>};
<a name="line102"></a>
<a name="line103"></a>
<a name="line104"></a>/**
<a name="line105"></a> * Retrieves the last modified date for this entry.
<a name="line106"></a> *
<a name="line107"></a> * @return {!goog.async.Deferred} The deferred Date for this entry. If an error
<a name="line108"></a> *     occurs, the errback is called with a {@link goog.fs.Error}.
<a name="line109"></a> */
<a name="line110"></a>goog.fs.Entry.prototype.getLastModified = function() {
<a name="line111"></a>  return this.getMetadata().addCallback(function(metadata) {
<a name="line112"></a>    return metadata.modificationTime;
<a name="line113"></a>  });
<a name="line114"></a>};
<a name="line115"></a>
<a name="line116"></a>
<a name="line117"></a>/**
<a name="line118"></a> * Retrieves the metadata for this entry.
<a name="line119"></a> *
<a name="line120"></a> * @return {!goog.async.Deferred} The deferred Metadata for this entry. If an
<a name="line121"></a> *     error occurs, the errback is called with a {@link goog.fs.Error}.
<a name="line122"></a> */
<a name="line123"></a>goog.fs.Entry.prototype.getMetadata = function() {
<a name="line124"></a>  var d = new goog.async.Deferred();
<a name="line125"></a>
<a name="line126"></a>  this.entry_.getMetadata(
<a name="line127"></a>      function(metadata) { d.callback(metadata); },
<a name="line128"></a>      goog.bind(function(err) {
<a name="line129"></a>        var msg = &#39;retrieving metadata for &#39; + this.getFullPath();
<a name="line130"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line131"></a>      }, this));
<a name="line132"></a>  return d;
<a name="line133"></a>};
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Move this entry to a new location.
<a name="line138"></a> *
<a name="line139"></a> * @param {!goog.fs.DirectoryEntry} parent The new parent directory.
<a name="line140"></a> * @param {string=} opt_newName The new name of the entry. If omitted, the entry
<a name="line141"></a> *     retains its original name.
<a name="line142"></a> * @return {!goog.async.Deferred} The deferred {@link goog.fs.FileEntry} or
<a name="line143"></a> *     {@link goog.fs.DirectoryEntry} for the new entry. If an error occurs, the
<a name="line144"></a> *     errback is called with a {@link goog.fs.Error}.
<a name="line145"></a> */
<a name="line146"></a>goog.fs.Entry.prototype.moveTo = function(parent, opt_newName) {
<a name="line147"></a>  var d = new goog.async.Deferred();
<a name="line148"></a>  this.entry_.moveTo(
<a name="line149"></a>      parent.dir_, opt_newName,
<a name="line150"></a>      goog.bind(function(entry) { d.callback(this.wrapEntry(entry)); }, this),
<a name="line151"></a>      goog.bind(function(err) {
<a name="line152"></a>        var msg = &#39;moving &#39; + this.getFullPath() + &#39; into &#39; +
<a name="line153"></a>            parent.getFullPath() +
<a name="line154"></a>            (opt_newName ? &#39;, renaming to &#39; + opt_newName : &#39;&#39;);
<a name="line155"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line156"></a>      }, this));
<a name="line157"></a>  return d;
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Copy this entry to a new location.
<a name="line163"></a> *
<a name="line164"></a> * @param {!goog.fs.DirectoryEntry} parent The new parent directory.
<a name="line165"></a> * @param {string=} opt_newName The name of the new entry. If omitted, the new
<a name="line166"></a> *     entry has the same name as the original.
<a name="line167"></a> * @return {!goog.async.Deferred} The deferred {@link goog.fs.FileEntry} or
<a name="line168"></a> *     {@link goog.fs.DirectoryEntry} for the new entry. If an error occurs, the
<a name="line169"></a> *     errback is called with a {@link goog.fs.Error}.
<a name="line170"></a> */
<a name="line171"></a>goog.fs.Entry.prototype.copyTo = function(parent, opt_newName) {
<a name="line172"></a>  var d = new goog.async.Deferred();
<a name="line173"></a>  this.entry_.copyTo(
<a name="line174"></a>      parent.dir_, opt_newName,
<a name="line175"></a>      goog.bind(function(entry) { d.callback(this.wrapEntry(entry)); }, this),
<a name="line176"></a>      goog.bind(function(err) {
<a name="line177"></a>        var msg = &#39;copying &#39; + this.getFullPath() + &#39; into &#39; +
<a name="line178"></a>            parent.getFullPath() +
<a name="line179"></a>            (opt_newName ? &#39;, renaming to &#39; + opt_newName : &#39;&#39;);
<a name="line180"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line181"></a>      }, this));
<a name="line182"></a>  return d;
<a name="line183"></a>};
<a name="line184"></a>
<a name="line185"></a>
<a name="line186"></a>/**
<a name="line187"></a> * Wrap an HTML5 entry object in an appropriate subclass instance.
<a name="line188"></a> *
<a name="line189"></a> * @param {!Entry} entry The underlying Entry object.
<a name="line190"></a> * @return {!goog.fs.Entry} The appropriate subclass wrapper.
<a name="line191"></a> * @protected
<a name="line192"></a> */
<a name="line193"></a>goog.fs.Entry.prototype.wrapEntry = function(entry) {
<a name="line194"></a>  return entry.isFile ?
<a name="line195"></a>      new goog.fs.FileEntry(this.fs_, /** @type {!FileEntry} */ (entry)) :
<a name="line196"></a>      new goog.fs.DirectoryEntry(
<a name="line197"></a>          this.fs_, /** @type {!DirectoryEntry} */ (entry));
<a name="line198"></a>};
<a name="line199"></a>
<a name="line200"></a>
<a name="line201"></a>/**
<a name="line202"></a> * Get the URL for this file.
<a name="line203"></a> *
<a name="line204"></a> * @param {string=} opt_mimeType The MIME type that will be served for the URL.
<a name="line205"></a> * @return {string} The URL.
<a name="line206"></a> */
<a name="line207"></a>goog.fs.Entry.prototype.toUrl = function(opt_mimeType) {
<a name="line208"></a>  return this.entry_.toURL(opt_mimeType);
<a name="line209"></a>};
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * Get the URI for this file.
<a name="line214"></a> *
<a name="line215"></a> * @deprecated Use {@link #toUrl} instead.
<a name="line216"></a> * @param {string=} opt_mimeType The MIME type that will be served for the URI.
<a name="line217"></a> * @return {string} The URI.
<a name="line218"></a> */
<a name="line219"></a>goog.fs.Entry.prototype.toUri = goog.fs.Entry.prototype.toUrl;
<a name="line220"></a>
<a name="line221"></a>
<a name="line222"></a>/**
<a name="line223"></a> * Remove this entry.
<a name="line224"></a> *
<a name="line225"></a> * @return {!goog.async.Deferred} A deferred object. If the removal succeeds,
<a name="line226"></a> *     the callback is called with true. If an error occurs, the errback is
<a name="line227"></a> *     called a {@link goog.fs.Error}.
<a name="line228"></a> */
<a name="line229"></a>goog.fs.Entry.prototype.remove = function() {
<a name="line230"></a>  var d = new goog.async.Deferred();
<a name="line231"></a>  this.entry_.remove(
<a name="line232"></a>      goog.bind(d.callback, d, true /* result */),
<a name="line233"></a>      goog.bind(function(err) {
<a name="line234"></a>        var msg = &#39;removing &#39; + this.getFullPath();
<a name="line235"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line236"></a>      }, this));
<a name="line237"></a>  return d;
<a name="line238"></a>};
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>/**
<a name="line242"></a> * Gets the parent directory.
<a name="line243"></a> *
<a name="line244"></a> * @return {!goog.async.Deferred} The deferred {@link goog.fs.DirectoryEntry}.
<a name="line245"></a> *     If an error occurs, the errback is called with a {@link goog.fs.Error}.
<a name="line246"></a> */
<a name="line247"></a>goog.fs.Entry.prototype.getParent = function() {
<a name="line248"></a>  var d = new goog.async.Deferred();
<a name="line249"></a>  this.entry_.getParent(
<a name="line250"></a>      goog.bind(function(parent) {
<a name="line251"></a>        d.callback(new goog.fs.DirectoryEntry(this.fs_, parent));
<a name="line252"></a>      }, this),
<a name="line253"></a>      goog.bind(function(err) {
<a name="line254"></a>        var msg = &#39;getting parent of &#39; + this.getFullPath();
<a name="line255"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line256"></a>      }, this));
<a name="line257"></a>  return d;
<a name="line258"></a>};
<a name="line259"></a>
<a name="line260"></a>
<a name="line261"></a>
<a name="line262"></a>/**
<a name="line263"></a> * A directory in a local FileSystem.
<a name="line264"></a> *
<a name="line265"></a> * This should not be instantiated directly. Instead, it should be accessed via
<a name="line266"></a> * {@link goog.fs.FileSystem#getRoot} or
<a name="line267"></a> * {@link goog.fs.DirectoryEntry#getDirectoryEntry}.
<a name="line268"></a> *
<a name="line269"></a> * @param {!goog.fs.FileSystem} fs The wrapped filesystem.
<a name="line270"></a> * @param {!DirectoryEntry} dir The underlying DirectoryEntry object.
<a name="line271"></a> * @constructor
<a name="line272"></a> * @extends {goog.fs.Entry}
<a name="line273"></a> */
<a name="line274"></a>goog.fs.DirectoryEntry = function(fs, dir) {
<a name="line275"></a>  goog.base(this, fs, dir);
<a name="line276"></a>
<a name="line277"></a>  /**
<a name="line278"></a>   * The underlying DirectoryEntry object.
<a name="line279"></a>   *
<a name="line280"></a>   * @type {!DirectoryEntry}
<a name="line281"></a>   * @private
<a name="line282"></a>   */
<a name="line283"></a>  this.dir_ = dir;
<a name="line284"></a>};
<a name="line285"></a>goog.inherits(goog.fs.DirectoryEntry, goog.fs.Entry);
<a name="line286"></a>
<a name="line287"></a>
<a name="line288"></a>/**
<a name="line289"></a> * Behaviors for getting files and directories.
<a name="line290"></a> * @enum {number}
<a name="line291"></a> */
<a name="line292"></a>goog.fs.DirectoryEntry.Behavior = {
<a name="line293"></a>  /**
<a name="line294"></a>   * Get the file if it exists, error out if it doesn&#39;t.
<a name="line295"></a>   */
<a name="line296"></a>  DEFAULT: 1,
<a name="line297"></a>  /**
<a name="line298"></a>   * Get the file if it exists, create it if it doesn&#39;t.
<a name="line299"></a>   */
<a name="line300"></a>  CREATE: 2,
<a name="line301"></a>  /**
<a name="line302"></a>   * Error out if the file exists, create it if it doesn&#39;t.
<a name="line303"></a>   */
<a name="line304"></a>  CREATE_EXCLUSIVE: 3
<a name="line305"></a>};
<a name="line306"></a>
<a name="line307"></a>
<a name="line308"></a>/**
<a name="line309"></a> * Get a file in the directory.
<a name="line310"></a> *
<a name="line311"></a> * @param {string} path The path to the file, relative to this directory.
<a name="line312"></a> * @param {goog.fs.DirectoryEntry.Behavior=} opt_behavior The behavior for
<a name="line313"></a> *     handling an existing file, or the lack thereof.
<a name="line314"></a> * @return {!goog.async.Deferred} The deferred {@link goog.fs.FileEntry}. If an
<a name="line315"></a> *     error occurs, the errback is called with a {@link goog.fs.Error}.
<a name="line316"></a> */
<a name="line317"></a>goog.fs.DirectoryEntry.prototype.getFile = function(path, opt_behavior) {
<a name="line318"></a>  var d = new goog.async.Deferred();
<a name="line319"></a>  this.dir_.getFile(
<a name="line320"></a>      path, this.getOptions_(opt_behavior),
<a name="line321"></a>      goog.bind(function(entry) {
<a name="line322"></a>        d.callback(new goog.fs.FileEntry(this.fs_, entry));
<a name="line323"></a>      }, this),
<a name="line324"></a>      goog.bind(function(err) {
<a name="line325"></a>        var msg = &#39;loading file &#39; + path + &#39; from &#39; + this.getFullPath();
<a name="line326"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line327"></a>      }, this));
<a name="line328"></a>  return d;
<a name="line329"></a>};
<a name="line330"></a>
<a name="line331"></a>
<a name="line332"></a>/**
<a name="line333"></a> * Get a directory within this directory.
<a name="line334"></a> *
<a name="line335"></a> * @param {string} path The path to the directory, relative to this directory.
<a name="line336"></a> * @param {goog.fs.DirectoryEntry.Behavior=} opt_behavior The behavior for
<a name="line337"></a> *     handling an existing directory, or the lack thereof.
<a name="line338"></a> * @return {!goog.async.Deferred} The deferred {@link goog.fs.DirectoryEntry}.
<a name="line339"></a> *     If an error occurs, the errback is called a {@link goog.fs.Error}.
<a name="line340"></a> */
<a name="line341"></a>goog.fs.DirectoryEntry.prototype.getDirectory = function(path, opt_behavior) {
<a name="line342"></a>  var d = new goog.async.Deferred();
<a name="line343"></a>  this.dir_.getDirectory(
<a name="line344"></a>      path, this.getOptions_(opt_behavior),
<a name="line345"></a>      goog.bind(function(entry) {
<a name="line346"></a>        d.callback(new goog.fs.DirectoryEntry(this.fs_, entry));
<a name="line347"></a>      }, this),
<a name="line348"></a>      goog.bind(function(err) {
<a name="line349"></a>        var msg = &#39;loading directory &#39; + path + &#39; from &#39; + this.getFullPath();
<a name="line350"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line351"></a>      }, this));
<a name="line352"></a>  return d;
<a name="line353"></a>};
<a name="line354"></a>
<a name="line355"></a>
<a name="line356"></a>/**
<a name="line357"></a> * Opens the directory for the specified path, creating the directory and any
<a name="line358"></a> * intermediate directories as necessary.
<a name="line359"></a> *
<a name="line360"></a> * @param {string} path The directory path to create. May be absolute or
<a name="line361"></a> *     relative to the current directory. The parent directory &quot;..&quot; and current
<a name="line362"></a> *     directory &quot;.&quot; are supported.
<a name="line363"></a> * @return {!goog.async.Deferred} A deferred {@link goog.fs.DirectoryEntry} for
<a name="line364"></a> *     the requested path. If an error occurs, the errback is called with a
<a name="line365"></a> *     {@link goog.fs.Error}.
<a name="line366"></a> */
<a name="line367"></a>goog.fs.DirectoryEntry.prototype.createPath = function(path) {
<a name="line368"></a>  // If the path begins at the root, reinvoke createPath on the root directory.
<a name="line369"></a>  if (goog.string.startsWith(path, &#39;/&#39;)) {
<a name="line370"></a>    var root = this.getFileSystem().getRoot();
<a name="line371"></a>    if (this.getFullPath() != root.getFullPath()) {
<a name="line372"></a>      return root.createPath(path);
<a name="line373"></a>    }
<a name="line374"></a>  }
<a name="line375"></a>
<a name="line376"></a>  // Filter out any empty path components caused by &#39;//&#39; or a leading slash.
<a name="line377"></a>  var parts = goog.array.filter(path.split(&#39;/&#39;), goog.functions.identity);
<a name="line378"></a>  var existed = [];
<a name="line379"></a>
<a name="line380"></a>  function getNextDirectory(dir) {
<a name="line381"></a>    if (!parts.length) {
<a name="line382"></a>      return goog.async.Deferred.succeed(dir);
<a name="line383"></a>    }
<a name="line384"></a>
<a name="line385"></a>    var def;
<a name="line386"></a>    var nextDir = parts.shift();
<a name="line387"></a>
<a name="line388"></a>    if (nextDir == &#39;..&#39;) {
<a name="line389"></a>      def = dir.getParent();
<a name="line390"></a>    } else if (nextDir == &#39;.&#39;) {
<a name="line391"></a>      def = goog.async.Deferred.succeed(dir);
<a name="line392"></a>    } else {
<a name="line393"></a>      def = dir.getDirectory(nextDir, goog.fs.DirectoryEntry.Behavior.CREATE);
<a name="line394"></a>    }
<a name="line395"></a>    return def.addCallback(getNextDirectory);
<a name="line396"></a>  }
<a name="line397"></a>
<a name="line398"></a>  return getNextDirectory(this);
<a name="line399"></a>};
<a name="line400"></a>
<a name="line401"></a>
<a name="line402"></a>/**
<a name="line403"></a> * Gets a list of all entries in this directory.
<a name="line404"></a> *
<a name="line405"></a> * @return {!goog.async.Deferred} The deferred list of {@link goog.fs.Entry}
<a name="line406"></a> *     results. If an error occurs, the errback is called with a
<a name="line407"></a> *     {@link goog.fs.Error}.
<a name="line408"></a> */
<a name="line409"></a>goog.fs.DirectoryEntry.prototype.listDirectory = function() {
<a name="line410"></a>  var d = new goog.async.Deferred();
<a name="line411"></a>  var reader = this.dir_.createReader();
<a name="line412"></a>  var results = [];
<a name="line413"></a>
<a name="line414"></a>  var errorCallback = goog.bind(function(err) {
<a name="line415"></a>    var msg = &#39;listing directory &#39; + this.getFullPath();
<a name="line416"></a>    d.errback(new goog.fs.Error(err.code, msg));
<a name="line417"></a>  }, this);
<a name="line418"></a>
<a name="line419"></a>  var successCallback = goog.bind(function(entries) {
<a name="line420"></a>    if (entries.length) {
<a name="line421"></a>      for (var i = 0, entry; entry = entries[i]; i++) {
<a name="line422"></a>        results.push(this.wrapEntry(entry));
<a name="line423"></a>      }
<a name="line424"></a>      reader.readEntries(successCallback, errorCallback);
<a name="line425"></a>    } else {
<a name="line426"></a>      d.callback(results);
<a name="line427"></a>    }
<a name="line428"></a>  }, this);
<a name="line429"></a>
<a name="line430"></a>  reader.readEntries(successCallback, errorCallback);
<a name="line431"></a>  return d;
<a name="line432"></a>};
<a name="line433"></a>
<a name="line434"></a>
<a name="line435"></a>/**
<a name="line436"></a> * Removes this directory and all its contents.
<a name="line437"></a> *
<a name="line438"></a> * @return {!goog.async.Deferred} A deferred object. If the removal succeeds,
<a name="line439"></a> *     the callback is called with true. If an error occurs, the errback is
<a name="line440"></a> *     called a {@link goog.fs.Error}.
<a name="line441"></a> */
<a name="line442"></a>goog.fs.DirectoryEntry.prototype.removeRecursively = function() {
<a name="line443"></a>  var d = new goog.async.Deferred();
<a name="line444"></a>  this.dir_.removeRecursively(
<a name="line445"></a>      goog.bind(d.callback, d, true /* result */),
<a name="line446"></a>      goog.bind(function(err) {
<a name="line447"></a>        var msg = &#39;removing &#39; + this.getFullPath() + &#39; recursively&#39;;
<a name="line448"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line449"></a>      }, this));
<a name="line450"></a>  return d;
<a name="line451"></a>};
<a name="line452"></a>
<a name="line453"></a>
<a name="line454"></a>/**
<a name="line455"></a> * Converts a value in the Behavior enum into an options object expected by the
<a name="line456"></a> * File API.
<a name="line457"></a> *
<a name="line458"></a> * @param {goog.fs.DirectoryEntry.Behavior=} opt_behavior The behavior for
<a name="line459"></a> *     existing files.
<a name="line460"></a> * @return {Object.&lt;boolean&gt;} The options object expected by the File API.
<a name="line461"></a> * @private
<a name="line462"></a> */
<a name="line463"></a>goog.fs.DirectoryEntry.prototype.getOptions_ = function(opt_behavior) {
<a name="line464"></a>  if (opt_behavior == goog.fs.DirectoryEntry.Behavior.CREATE) {
<a name="line465"></a>    return {&#39;create&#39;: true};
<a name="line466"></a>  } else if (opt_behavior == goog.fs.DirectoryEntry.Behavior.CREATE_EXCLUSIVE) {
<a name="line467"></a>    return {&#39;create&#39;: true, &#39;exclusive&#39;: true};
<a name="line468"></a>  } else {
<a name="line469"></a>    return {};
<a name="line470"></a>  }
<a name="line471"></a>};
<a name="line472"></a>
<a name="line473"></a>
<a name="line474"></a>
<a name="line475"></a>/**
<a name="line476"></a> * A file in a local filesystem.
<a name="line477"></a> *
<a name="line478"></a> * This should not be instantiated directly. Instead, it should be accessed via
<a name="line479"></a> * {@link goog.fs.DirectoryEntry#getDirectoryEntry}.
<a name="line480"></a> *
<a name="line481"></a> * @param {!goog.fs.FileSystem} fs The wrapped filesystem.
<a name="line482"></a> * @param {!FileEntry} file The underlying FileEntry object.
<a name="line483"></a> * @constructor
<a name="line484"></a> * @extends {goog.fs.Entry}
<a name="line485"></a> */
<a name="line486"></a>goog.fs.FileEntry = function(fs, file) {
<a name="line487"></a>  goog.base(this, fs, file);
<a name="line488"></a>
<a name="line489"></a>  /**
<a name="line490"></a>   * The underlying FileEntry object.
<a name="line491"></a>   *
<a name="line492"></a>   * @type {!FileEntry}
<a name="line493"></a>   * @private
<a name="line494"></a>   */
<a name="line495"></a>  this.file_ = file;
<a name="line496"></a>};
<a name="line497"></a>goog.inherits(goog.fs.FileEntry, goog.fs.Entry);
<a name="line498"></a>
<a name="line499"></a>
<a name="line500"></a>/**
<a name="line501"></a> * Create a writer for writing to the file.
<a name="line502"></a> *
<a name="line503"></a> * @return {!goog.async.Deferred} The deferred {@link goog.fs.FileWriter}. If an
<a name="line504"></a> *     error occurs, the errback is called with a {@link goog.fs.Error}.
<a name="line505"></a> */
<a name="line506"></a>goog.fs.FileEntry.prototype.createWriter = function() {
<a name="line507"></a>  var d = new goog.async.Deferred();
<a name="line508"></a>  this.file_.createWriter(
<a name="line509"></a>      function(w) { d.callback(new goog.fs.FileWriter(w)); },
<a name="line510"></a>      goog.bind(function(err) {
<a name="line511"></a>        var msg = &#39;creating writer for &#39; + this.getFullPath();
<a name="line512"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line513"></a>      }, this));
<a name="line514"></a>  return d;
<a name="line515"></a>};
<a name="line516"></a>
<a name="line517"></a>
<a name="line518"></a>/**
<a name="line519"></a> * Get the file contents as a File blob.
<a name="line520"></a> *
<a name="line521"></a> * @return {!goog.async.Deferred} The deferred File. If an error occurs, the
<a name="line522"></a> *     errback is called with a {@link goog.fs.Error}.
<a name="line523"></a> */
<a name="line524"></a>goog.fs.FileEntry.prototype.file = function() {
<a name="line525"></a>  var d = new goog.async.Deferred();
<a name="line526"></a>  this.file_.file(
<a name="line527"></a>      function(f) { d.callback(f); },
<a name="line528"></a>      goog.bind(function(err) {
<a name="line529"></a>        var msg = &#39;getting file for &#39; + this.getFullPath();
<a name="line530"></a>        d.errback(new goog.fs.Error(err.code, msg));
<a name="line531"></a>      }, this));
<a name="line532"></a>  return d;
<a name="line533"></a>};
</pre>


</body>
</html>
